package simpleserver;

//Tue Nov  2 18:34:53 EST 2004
//
//Written by Sean R. Owens, sean at guild dot net, released to the
//public domain.  Share and enjoy.  Since some people argue that it is
//impossible to release software to the public domain, you are also free
//to use this code under any version of the GPL, LPGL, or BSD licenses,
//or contact me for use of another license.
//http://darksleep.com/player

import java.net.Socket;
import java.util.Date;
import java.io.InputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.IOException;

import javax.naming.BinaryRefAddr;

public class VerySimpleClient {
	private String serverHostname = null;
	private int serverPort = 0;
	private Socket sock = null;
	private InputStream sockInput = null;
	private OutputStream sockOutput = null;

	public VerySimpleClient(String serverHostname, int serverPort, byte[] data) {
		this.serverHostname = serverHostname;
		this.serverPort = serverPort;
	}

	public boolean sendSomeMessages() {
		System.err.println("Opening connection to " + serverHostname + " port "
				+ serverPort);
		try {
			sock = new Socket(serverHostname, serverPort);
			sockOutput = sock.getOutputStream();
		} catch (IOException e) {
			System.out.println("keine Verbindung hergestellt");
			return false;
		}

		
		ObjectOutputStream oos;
		
		try {
			oos = new ObjectOutputStream(sockOutput);
			
			

			oos.writeInt(12345);
			oos.writeUTF("Today");
			oos.writeObject(new Date());

			oos.close();
			System.out.println("geschrieben");

		} catch (IOException e1) {
			e1.printStackTrace();
			return false;
		}

		try {
			sock.close();
		} catch (IOException e) {
			System.err.println("Exception closing socket.");
			e.printStackTrace(System.err);
			return false;
		}
		System.err.println("Exiting.");
		return true;
	}

	public static void main(String argv[]) {
		String hostname = "localhost";
		int port = 54000;
		byte[] data = "Hello World".getBytes();

		VerySimpleClient client = new VerySimpleClient(hostname, port, data);
		System.out.println(client.sendSomeMessages());
	}
}